#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

long long read() {
    long long  x = 0;
    char ch = getchar();
    for (; ch >= 48 && ch <= 57; x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar());
    return x;
}

struct Node {
    long long freq;
    int depth;

    bool operator>(const Node& other) const {
        if (freq != other.freq) {
            return freq > other.freq;
        }
        return depth > other.depth;
    }
};

/**
 * https://www.luogu.com.cn/problem/P2168
 */
int main() {

    priority_queue<Node, vector<Node>, greater<>> q;

    const long long n = read();
    const long long k = read();

    // 计算需要添加的虚拟节点数
    long long d = 0;
    long long r = (n - 1) % (k - 1);
	if (r != 0) {
		d = static_cast<long long>(ceil((n - 1) / (k - 1.0))) * (k - 1) - (n - 1);
    }

    // 添加虚拟节点
    for (long long i = 0; i < d; i++) {
        q.push({ 0, 0 });
    }

    for (int i = 1; i <= n; i++) {
        const long long freq = read();
        q.push({ freq, 0 });
    }

    long long totalCost = 0;
    int maxDepth = 0;

    // 合并节点直到只剩一个
    while (q.size() > 1) {
        long long sum = 0;
        int groupMaxDepth = 0;

        // 取出k个节点
        for (int i = 0; i < k; i++) {
            Node node = q.top();
            q.pop();
            sum += node.freq;
            groupMaxDepth = max(groupMaxDepth, node.depth);
        }

        totalCost += sum;
        int newDepth = groupMaxDepth + 1;
        maxDepth = max(maxDepth, newDepth);

        // 创建新节点
        q.push({ sum, newDepth });
    }

    printf("%lld\n%d", totalCost, maxDepth);

    return 0;
}